void main() {
  //typedef可以用作引用函数的指针，官方示例
  ManyOperation oper;
  //可以指向具有相同函数签名的方法在内存的地址
  //函数签名由函数的参数(包括其类型，区分父类、子类)定义。返回类型不是函数签名的一部分
  oper = Add;
  oper(10, 20);
  oper = Subtract;
  oper(30, 20);
  oper = Divide;
  oper(50, 5);
  //可以当做参数传递
  Calculator(10, 20, Add);
  Calculator(30, 20, Subtract);
  Calculator(50, 5, Divide);

  //示例
  Bird bird = Bird((int a) {//如果实参函数的类型不是该类型的话 编译不通过
    print(a);
  });
  bird.fly(3);
}

typedef ManyOperation(int first, int second);

Add(int first, int second) {
  print("Add result is ${first + second}");
}

Subtract(int first, int second) {
  print("Subtract result is ${first - second}");
}

Divide(int first, int second) {
  print("Add result is ${first / second}");
}

Calculator(int first, int second, ManyOperation oper) {
  print("Inside calculator");
  oper(first, second);
}

typedef Fly = void Function(int value);

class Bird {
  Fly fly;

  Bird(this.fly);
}
